﻿@using X.PagedList
@using X.PagedList.Mvc.Core
@model IPagedList<Mvc.Sample.Models.TodoItem>
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
    ViewData["Title"] = "Index";
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>Item Index</title>
    <link href="~/lib/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<div class="container mt-5">
    <h2 class="text-center">Index</h2>
    <div class="">
        <form class="d-inline" asp-area="Todo" asp-action="Index" asp-controller="Home" method="get">
            Title: <input type="text" value="@Context.Request.Query["title"]" name="title" style="display: inline; max-width: 280px;" class="form-control" />
            <button class="btn btn-success" type="submit">Search</button>
        </form>
    </div>
    <hr />
    <a class="btn btn-primary mb-3" href="@Url.Action("Create", "Home")">Add Item</a>
    <table class="table table-bordered">
        <thead class="table-light">
        <tr>
            <th>ID</th>
            <th>Title</th>
            <th>Description</th>
            <th>Is Done</th>
            <th>Due Date</th>
            <th>Actions</th>
        </tr>
        </thead>
        <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>@item.Id</td>
                <td>@item.Title</td>
                <td>@item.Description</td>
                <td>@(item.IsDone ? "Yes" : "No")</td>
                <td>@item.DueDate.ToShortDateString()</td>
                <td>
                    <a class="btn btn-warning btn-sm" href="@Url.Action("Edit", "Home", new { id = item.Id})">Edit</a>
                    <form asp-area="Todo" asp-controller="Home" asp-action="Delete" asp-route-id="@item.Id" method="post" style="display:inline;">
	                    <button type="submit" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure?')">Delete</button>
                    </form>
                    <a class="btn btn-info btn-sm" href="@Url.Action("Details", "Home", new { id = item.Id})">Details</a>
                </td>
            </tr>
        }
        </tbody>
    </table>
    <div class="pagination">
        <div> 
            @Html.PagedListPager(Model, page => Url.Action("Index","Home", new { page, title = Context.Request.Query["title"] }),
                new PagedListRenderOptions
                {
                    LiElementClasses = ["page-item"],
                    PageClasses = ["page-link"],
                    DisplayLinkToFirstPage = PagedListDisplayMode.Always,
                    DisplayLinkToLastPage = PagedListDisplayMode.Always,
                    DisplayLinkToPreviousPage = PagedListDisplayMode.Always,
                    DisplayLinkToNextPage = PagedListDisplayMode.Always,
                    ContainerDivClasses = ["pagination"],
                    UlElementClasses = ["pagination mb-0"],
                    LinkToFirstPageFormat = "First",
                    LinkToPreviousPageFormat = "Previous",
                    LinkToNextPageFormat = "Next",
                    LinkToLastPageFormat = "Last",
                })
        </div>
    </div>
</div>
<script src="~/lib/jquery/dist/jquery.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
